package cn.stylefeng.guns.modular.system.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.system.entity.Store;
import cn.stylefeng.guns.modular.system.entity.UpShop;
import cn.stylefeng.guns.modular.system.mapper.StoreMapper;
import cn.stylefeng.guns.modular.system.mapper.UpShopMapper;
import cn.stylefeng.guns.modular.system.model.params.UpShopParam;
import cn.stylefeng.guns.modular.system.service.UpShopService;
import cn.stylefeng.guns.sys.core.shiro.ShiroKit;
import cn.stylefeng.guns.sys.core.util.common.ResponseMsg;
import cn.stylefeng.guns.sys.core.util.common.SystemConstant;
import cn.stylefeng.guns.sys.core.util.common.UploadFileUtils;
import cn.stylefeng.guns.sys.core.util.common.UploadResult;
import cn.stylefeng.guns.sys.modular.system.mapper.DeptMapper;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;


/**
 * 开店申请表控制器
 *
 * @author 小飞
 * @Date 2019-07-11 03:14:13
 */
@Controller
@RequestMapping("/upShop")
public class UpShopController extends BaseController {

    private String PREFIX = "/upShop";

    @Autowired
    private UpShopService upShopService;
    @Autowired
    private DeptMapper deptMapper;
    @Autowired
    private UpShopMapper upShopMapper;
    @Autowired
    private StoreMapper storeMapper;


    /**
     * 跳转到主页面
     *
     * @author 小飞
     * @Date 2019-07-11
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/upShop.html";
    }

    /**
     * 新增页面
     *
     * @author 小飞
     * @Date 2019-07-11
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/upShop_add.html";
    }

    /**
     * 编辑页面
     *
     * @author 小飞
     * @Date 2019-07-11
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/upShop_edit.html";
    }

    /**
     * 新增接口
     *
     * @author 小飞
     * @Date 2019-07-11
     */
//    @RequestMapping("/addItem")
//    @ResponseBody
//    public ResponseData addItem(UpShopParam upShopParam) {
//
//        UpShop upShop = new UpShop();
//        upShop.setTime(new Date());
//        upShop.setRemark(upShopParam.getRemark());
//        upShop.setStoreId(upShopParam.getStoreId());
//        upShop.setPaperPath(upShopParam.getPaperPath());
//        upShop.setLoginNum(upShopParam.getLoginNum());
//        upShop.setCheckCode(1);
//        upShop.setCommentShop(upShopParam.getCommentShop());
//        upShopMapper.insert(upShop);
//
//        //门店表
//        Store store = new Store();
//
//        store.setStoreName(upShopParam.getStoreName());
//        //附件
//        store.setAccessoryPath(upShopParam.getAccessoryPath());
//        store.setStorelatitude(upShopParam.getStorelatitude());
//        store.setStoreLongtitude(upShopParam.getStoreLongtitude());
//        store.getAcountNum(upShopParam.getAcountNum());
//        store.setPicPath(upShopParam.getPicPath());
//        store.setCash(upShopParam.getCash());
//        store.setAddressDetail(upShopParam.getAddressDetail());
//
//        storeMapper.insert(store);
//
//        return ResponseData.success();
//    }

    /**
     * 编辑接口
     * 修改
     * @author 小飞
     * @Date 2019-07-11
     */
//    @RequestMapping("/editItem")
////    @ResponseBody
////    public ResponseData editItem(UpShopParam upShopParam) {
////        UpShop upShop = new UpShop();
////        upShop.setUserId(upShopParam.getUserId());
////        upShop.setRemark(upShopParam.getRemark());
////        upShop.setPaperPath(upShopParam.getPaperPath());
////        upShop.setLoginNum(upShopParam.getLoginNum());
////        upShop.setCommentShop(upShopParam.getCommentShop());
////        upShop.setStoreId(upShopParam.getId());
////        int a = upShopService.UpdateUpShopId(upShop);
////        return ResponseData.success();
////    }

    /**
     * 删除接口
     *
     * @author 小飞
     * @Date 2019-07-11
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(UpShopParam upShopParam) {
        this.upShopService.delete(upShopParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author 小飞
     * @Date 2019-07-11
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(UpShopParam upShopParam) {
        UpShop detail = this.upShopService.getById(upShopParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author 小飞
     * @Date 2019-07-11
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(UpShopParam upShopParam) {
        return this.upShopService.findPageBySpec(upShopParam);
    }


    @RequestMapping("/uploadFile")
    public ResponseEntity<?> uploadFile(MultipartFile multipartFile){
        ResponseMsg msg = new ResponseMsg();
        msg = UploadFileUtils.uploadFile(multipartFile);
        if (msg.getStatus() == 10001){
            UploadResult uploadResult = (UploadResult) msg.getResult();
            msg.setStatus(10001);
            msg.setDesc("上传成功");
            msg.setResult(SystemConstant.TENCENT_URL + uploadResult.getPath());
            return  new ResponseEntity<>(msg, HttpStatus.OK);
        }else {
            msg.setDesc("上传失败");
            msg.setStatus(10002);
            return  new ResponseEntity<>(msg,HttpStatus.OK);
        }
    }









}


